package com.ccc.dingtalk.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.TimeZone;

/**
 * 服务启动时控制台打印信息工具类
 *
 * @author superC
 * @version 2.0.0
 * @date 2023/3/12
 */

@Component
public class AppStartUtil {
    protected static final Logger logger = LoggerFactory.getLogger(AppStartUtil.class);

    private static String active;

    @Value("${spring.profiles.active}")
    public void setActive(String active) {
        AppStartUtil.active = active;
    }

    private static String port;

    @Value("${server.port}")
    public void setPort(String port) {
        AppStartUtil.port = port;
    }

    public static void start() {
        AppStartUtil.setTimeZone();
        AppStartUtil.print();
    }

    public static void setTimeZone() {
        // 启动类中，配置时区
        TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
    }

    public static void print() {
        logger.info("\r\n" +
                "**********************************************************\r\n" +
                ":: 服务名称                   :: " + MyProjectProperties.getArtifactId() + "\r\n" +
                ":: 服务描述                   :: " + MyProjectProperties.getDescription() + "\r\n" +
                ":: 服务版本                   :: " + MyProjectProperties.getVersion() + "\r\n" +
                ":: 服务端口                   :: " + port + "\r\n" +
                ":: Spring运行环境             :: " + active + "\r\n" +
                ":: 当前时区                 :: " + TimeZone.getDefault().getID() + " - " + TimeZone.getDefault().getDisplayName() + "\r\n" +
                ":: 启动时间                 :: " + LocalDateTime.now() + "\r\n" +
                "**********************************************************\r\n" +
                "********************** 服务启动完毕 ************************");
    }

}